package action.contract;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

//import model.TContract;
import model.company.Companybasic;
import model.company.Companycontact;
import model.company.Companytopmanager;
import model.contract.Contractmortgage;
import model.personal.Personalbasic;
import service.app.InfoService;
import service.contract.ContractService;
import service.contract.ShowContractService;
import tool.WordDownload;
import util.Tool;
import exception.Exceptions;

public class ContractMortgagePrintAction {
	private String fileName;
	private Integer id;
	private ShowContractService showContractService;
	private ContractService contractService;
	private InfoService infoService;
	public InputStream getInputStream() throws Exceptions {
		Contractmortgage contractmortgage=showContractService.get_htMortgage(id);
		String contractid=contractmortgage.getMortgageid();
		setFileName(Tool.toChinese(contractid+".doc"));
		Map<String, String> map=new HashMap<String, String>();
		map.put("contractid", contractid);//显示的东西
		//TContract contractloan=showContractService.get_ht("contractid",contractmortgage.getContractloanid());
		//Companybasic company=new Companybasic();
		//company=contractService.get_companybasic(contractloan.getClientid());
		//Companycontact companycontact=contractService.get_companycontact(contractloan.getClientid());
		//map.put("customname",company.getName());
		//map.put("address",company.getRegaddress());
		//map.put("phone",companycontact.getTelephone());
		//map.put("fax",companycontact.getFax());
		//Companytopmanager topmanager=contractService.get_topmanager("cid="+company.getId()+"and category=1");
		//map.put("representative",topmanager.getName());
		//map.put("position","法人代表");
		if(contractmortgage.getCustommortgagetype().equals("1")){
			Personalbasic personal=new Personalbasic();
			personal=contractService.get_personalbasic(contractmortgage.getCustommortgageid());
			map.put("custommortgagename",personal.getName());
			map.put("cardtype", "身份证？？");
			map.put("cardnum", personal.getCertificatenumber());
			map.put("mortgageaddress",personal.getCurrentresidentialaddress());
			map.put("mortgagephone",personal.getHomephone());
			map.put("mortgagefax","");	
			map.put("mortgagerepresentative","");
			map.put("mortgageposition","");
		}
		if(contractmortgage.getCustommortgagetype().equals("2")){
			Companybasic companymortgage=new Companybasic();
			companymortgage=contractService.get_companybasic(contractmortgage.getCustommortgageid());
			Companycontact companycontactmortgage=contractService.get_companycontact(contractmortgage.getCustommortgageid());
			map.put("custommortgagename",companymortgage.getName());
			map.put("cardtype", "");
			map.put("cardnum", "");
			map.put("mortgageaddress",companymortgage.getRegaddress());
			map.put("mortgagephone",companycontactmortgage.getTelephone());
			map.put("mortgagefax",companycontactmortgage.getFax());
			Companytopmanager topmanagermortgage=contractService.get_topmanager("cid="+companymortgage.getId()+"and category=1");
			map.put("mortgagerepresentative",topmanagermortgage.getName());
			map.put("mortgageposition","法人代表");
		}
		map.put("companyname",infoService.getInfo("companyname"));
		map.put("companyaddress", infoService.getInfo("address"));
		map.put("companyphone", infoService.getInfo("phone"));
		map.put("companyfax", infoService.getInfo("fax"));
		WordDownload www=new WordDownload();
		www.setWord(map,"htmortgage");//ht存在的WORD的名字
        return www.run();
	}
	public String execute(){
		return "success";
	}
	public String getFileName() {
		return fileName;
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public ShowContractService getShowContractService() {
		return showContractService;
	}
	public void setShowContractService(ShowContractService showContractService) {
		this.showContractService = showContractService;
	}
	public ContractService getContractService() {
		return contractService;
	}
	public void setContractService(ContractService contractService) {
		this.contractService = contractService;
	}
	public InfoService getInfoService() {
		return infoService;
	}

	public void setInfoService(InfoService infoService) {
		this.infoService = infoService;
	}

}
